//
//  FnumTableViewCell.m
//  LoveOfPet
//
//  Created by 芦彬 on 15/11/20.
//  Copyright © 2015年 孔维. All rights reserved.
//

#import "FnumTableViewCell.h"
#import "LuBDefine.h"
#import "SDWebImageManager.h"
#import "UIImageView+WebCache.h"

@implementation FnumTableViewCell

- (void)dealloc{
    [_fnums release];
    [_avatarImageView release];
    [_sexLabel release];
    [_firstLabel release];
    [_secondLabel release];
    [super dealloc];
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self createFnumTableViewCell];
    }
    return self;
}

- (void)createFnumTableViewCell{
    self.selectionStyle = UITableViewCellSelectionStyleNone;
    
    self.avatarImageView = [[UIImageView alloc]init];
    self.avatarImageView.backgroundColor = [UIColor redColor];
    [self addSubview:_avatarImageView];
    [_avatarImageView release];
    
    self.sexLabel = [[UILabel alloc]init];
//    self.sexLabel.backgroundColor = [UIColor redColor];
    [self addSubview:_sexLabel];
    [_sexLabel release];
    
    self.firstLabel = [[UILabel alloc]init];
//    self.firstLabel.backgroundColor = [UIColor orangeColor];
    [self addSubview:_firstLabel];
    [_firstLabel release];
    
    self.secondLabel = [[UILabel alloc]init];
//    self.secondLabel.backgroundColor = [UIColor orangeColor];
    [self addSubview:_secondLabel];
    [_secondLabel release];
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
    self.avatarImageView.frame = CGRectMake(10, 10, WIDTH / 8, WIDTH / 8);
    
    self.sexLabel.frame = CGRectMake(20 + self.avatarImageView.frame.size.width, 10, 40, 20);
    self.sexLabel.font = [UIFont systemFontOfSize: 14];
    
    self.firstLabel.frame = CGRectMake(20 + self.avatarImageView.frame.size.width + self.sexLabel.frame.size.width, 10, WIDTH - 30 -self.avatarImageView.frame.size.width, 20);
    self.firstLabel.font = [UIFont systemFontOfSize:14];
    
    self.secondLabel.frame = CGRectMake(20 + self.avatarImageView.frame.size.width, 20 + self.firstLabel.frame.size.height, WIDTH - 30 -self.avatarImageView.frame.size.width, 20);
    self.secondLabel.font = [UIFont systemFontOfSize:12];
    self.secondLabel.textColor = [UIColor grayColor];
}

- (void)setFnums:(Fnums *)fnums{
    if (_fnums != fnums) {
        [_fnums release];
        _fnums = [fnums retain];
    }
    NSURL *avatarUrl = [NSURL URLWithString:fnums.avatar];
    [self.avatarImageView sd_setImageWithURL:avatarUrl placeholderImage:[UIImage imageNamed:@"zhanweitu.jpg"]];
    
    if ([fnums.sex isEqualToString:@"1"]) {
        self.sexLabel.text = [NSString stringWithFormat:@"🎩公"];
    }else{
        self.sexLabel.text = [NSString stringWithFormat:@"🎀母"];
    }
    self.firstLabel.text = [NSString stringWithFormat:@"{%@}的%@",fnums.nickname, fnums.petname];
    self.secondLabel.text = [NSString stringWithFormat:@"品种:%@   年龄:%@",fnums.type_name, fnums.age];
    
}

+ (FnumTableViewCell *)fnumtableViewWithTableView:(UITableView *)tableView{
    static NSString *fnumCell = @"fnumCell";
    FnumTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:fnumCell];
    if (!cell) {
        cell = [[[FnumTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:fnumCell] autorelease];
    }
    return cell;
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
